home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / Zkrolly demo ƒ / Zkrolly.p < prev    next >
Encoding:
Text File  |  1995-01-17  |  2.9 KB  |  101 lines  |  [TEXT/PJMM]

  1. program Zkrolly;
  2.     uses
  3. {$ifc UNDEFINED THINK_PASCAL}
  4.         Types, QuickDraw, Fonts, Windows, Dialogs, OSUtils, Memory, {}
  5. {$endc}
  6.         SAT, sXprite, sZprite;
  7.  
  8.     var
  9.         ignoresp, zp: SpritePtr;
  10.         zWind: WindowPtr;
  11.         r: Rect;
  12.  
  13.     const
  14.         scrollSizeH = 200;
  15.         scrollSizeV = 150;
  16.  
  17.     function IsOptionPressed: Boolean;
  18.         var
  19.             km: KeyMap;
  20.     begin
  21.         GetKeys(km);
  22.         IsOptionPressed := km[58];
  23.     end;
  24.  
  25.     function Zyncho: Boolean;
  26.         var
  27.             where, dest: Rect;
  28.     begin
  29.         where.topLeft := zp^.position;
  30.         where.left := where.left - scrollSizeH div 2;
  31.         where.top := where.top - scrollSizeV div 2;
  32.         if where.left < 0 then
  33.             where.left := 0;
  34.         if where.top < 0 then
  35.             where.top := 0;
  36.         if where.left + scrollSizeH > gSAT.offSizeH then
  37.             where.left := gSAT.offSizeH - scrollSizeH;
  38.         if where.top + scrollSizeV > gSAT.offSizeV then
  39.             where.top := gSAT.offSizeV - scrollSizeV;
  40.         where.bottom := where.top + scrollSizeV;
  41.         where.right := where.left + scrollSizeH;
  42.         SetRect(dest, 0, 0, scrollSizeH, scrollSizeV);
  43.  
  44.         CopyBits(gSAT.offScreen.port^.portBits, gSAT.wind.port^.portBits, where, dest, srcCopy, nil);
  45.  
  46. {SATCopyBitsToScreen is obsolete - CopyBits is at least as fast for large areas anyway.}
  47. {For scrolling games, we must use other methods for improving the frame rate, like interlacing.}
  48.  
  49. {SATCopyBitsToScreen(gSAT.offScreen, where, dest, IsOptionPressed);}
  50. {Note that there's hardly any speed difference between fast and safe mode when copying areas this big!}
  51.  
  52.         Zyncho := true; {Tell SAT not to draw on-screen: we do that ourselves!}
  53.     end;
  54.  
  55.     procedure SetupZwind;
  56.         var
  57.             zr: Rect;
  58.             wrld: SysEnvRec;
  59.     begin
  60. {Since SAT hasn't been initialized yet, we can't use gSAT.colorFlag but have to check environs ourselves.}
  61.         if noErr <> SysEnvirons(1, wrld) then
  62.             ; {ignore errors}
  63.         SetRect(zr, 20, 30, 20 + scrollSizeH, 30 + scrollSizeV);
  64.         if wrld.hasColorQD then
  65.             Zwind := NewCWindow(nil, zr, '', false, plainDBox, WindowPtr(-1), false, 0)
  66.         else
  67.             Zwind := NewWindow(nil, zr, '', false, plainDBox, WindowPtr(-1), false, 0);
  68.     end;
  69.  
  70. begin
  71. {In case this isn't Think Pascal we have to make the standard inits ourselves.}
  72. {$IFC UNDEFINED THINK_PASCAL}
  73.     SATInitToolbox;
  74. {$ENDC}
  75.  
  76.     SetupZwind;
  77.  
  78.     SetRect(r, 0, 0, 510, 340);
  79.     SATCustomInit(128, 129, r, zwind, nil, false, false, false, true, false);
  80.     InitXprite;
  81.     InitZprite;
  82.     ShowWindow(gSAT.wind.port);
  83.     SelectWindow(gSAT.wind.port);
  84.     SATInstallSynch(@Zyncho);
  85.     zp := SATNewSprite(0, 90, 70, @SetupZprite);
  86.     ignoresp := SATNewSprite(0, 120, 100, @SetupXprite);
  87.     ignoresp := SATNewSprite(0, 200, 160, @SetupXprite);
  88.     SATSetPortScreen;
  89.     repeat
  90.         SATRun(IsOptionPressed);
  91.     until Button;
  92.  
  93. {WARNING! It seems like we mess up the current device somewhere. Probably a bug in SAT}
  94. {(where the device setting isn't perfect yet). Let's set port and device to something nice}
  95. {and safe!}
  96.     SetPort(gSAT.wind.port);
  97.     if gSAT.colorFlag then
  98.         SetGDevice(GetMainDevice);
  99. { Finally, make sure we dispose of the sound channel. }
  100.     SATSoundShutup;
  101. end.